package com.pospi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.pospi.dto.PayWayDto;
import com.pospi.pai.yunpos.R;
import com.pospi.util.constant.PayWay;

import java.util.List;

/**
 * Created by acer on 2018/8/14.
 */

public class PayAdapter extends BaseAdapter {
    private List<PayWayDto> dtos;
    private Context context;

    public PayAdapter(List<PayWayDto> dtos, Context context) {
        this.dtos = dtos;
        this.context = context;
    }

    @Override
    public int getCount() {
        return dtos.size();
    }

    @Override
    public Object getItem(int position) {
        return dtos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(context).inflate(R.layout.pay_way_listitem, null);
            holder.iv = convertView.findViewById(R.id.iv_img);
            holder.tv = convertView.findViewById(R.id.tv_name);
            holder.ll_item = convertView.findViewById(R.id.ll_item);
            convertView.setTag(holder);

        } else {
            holder = (Holder) convertView.getTag();
        }
        if (dtos.get(position).getStatus() == 1) {
            holder.ll_item.setBackground(context.getResources().getDrawable(R.drawable.bt_press));
            holder.tv.setTextColor(context.getResources().getColor(R.color.white));
            switch (dtos.get(position).getPayType1()) {
                case PayWay.ALIPAY:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_zfb_selected);
                    break;
                case PayWay.WXPAY:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_wx_selected);
                    break;
                case PayWay.CASH:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_xj_selected);
                    break;
                case PayWay.BANK_CARD:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_yhk_selected);
                    break;
                case PayWay.JF_CODE:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_jf_selected);
                    break;
                case PayWay.YHQ_CODE:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_yhq_selected);
                    break;
                case PayWay.MIANZHI_CARD:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_yhk_selected);
                    break;
            }
        } else {
            holder.ll_item.setBackground(context.getResources().getDrawable(R.drawable.yj_white_2));
            holder.tv.setTextColor(context.getResources().getColor(R.color.DimGray));
            switch (dtos.get(position).getPayType1()) {
                case PayWay.ALIPAY:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_zfb_nor);
                    break;
                case PayWay.WXPAY:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_wx_nor);
                    break;
                case PayWay.CASH:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_xj_nor);
                    break;
                case PayWay.BANK_CARD:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_yhk_nor);
                    break;
                case PayWay.JF_CODE:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_jf_nor);
                    break;
                case PayWay.YHQ_CODE:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_yhq_nor);
                    break;
                case PayWay.MIANZHI_CARD:
                    holder.iv.setImageResource(R.drawable.icon_zfpt_yhk_nor);
                    break;
            }
        }
        holder.tv.setText(dtos.get(position).getName());

        return convertView;
    }
    class Holder{
        ImageView iv;
        TextView tv;
        LinearLayout ll_item;
    }
}
